#include "City.h"


City::City(){

}

City::City(string name) {
    setCity(name);
}



City::~City(){

}


bool onlyLetters(string phrase) {
    for (unsigned short i=0; i < phrase.size(); i++) {
        if(!isalpha(phrase[i]) || !isspace(phrase[i]))
            return false;
    }
    return true;
}


string City::getName() const{
    return name;
}

/// Only contains normal characters (no numbers nor symbols).
void City::setName(string name){
    if (!onlyLetters(name))
        throw InvalidCityName(name);

    if (name.size() > 100)
        throw InvalidCityName(name);

    this->name = name;
}

string City::printCity() {
    string info = this->getName();
    return info;
}

void City::newCity(City & city) {
    bool error = true;

    while(error) {
        error = false;
        cout << "\nCity name: ";

        try {
            string name;
            cin >> name;
            city.setName(name);

        } catch(City::InvalidCityName x) {
            x.printError(cerr);
            error = true;
        }
    }
}
